package com.xinzhi.pojo;

import com.baomidou.mybatisplus.annotation.EnumValue;
import com.baomidou.mybatisplus.annotation.IEnum;
import com.fasterxml.jackson.annotation.JsonValue;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor
@AllArgsConstructor
public enum SexEnum implements IEnum<String> {
    /**
     * 0表示未知 1表示男 2表示女
     */
    womale(0,"女"),
    male(1,"男");
    @EnumValue
    private int code;
    @JsonValue
    private String sexStr;

    @Override
    public String toString() {
        return sexStr;
    }

    @Override
    public String getValue() {
        Integer value =code;
        return value.toString();
    }


    // 根据整数值获取枚举
    public static SexEnum fromCode(int code) {
        for (SexEnum sex : SexEnum.values()) {
            if (sex.getCode() == code) {
                return sex;
            }
        }
        throw new IllegalArgumentException("No enum constant with code " + code);
    }
}



